home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / EX3_12.C < prev    next >
C/C++ Source or Header  |  1992-08-20  |  2KB  |  44 lines

  1. // Copyright (C) 1991 Texas Instruments Incorporated.
  2. //
  3. // Permission is granted to any individual or institution to use, copy, modify,
  4. // and distribute this software, provided that this complete copyright and
  5. // permission notice is maintained, intact, in all copies and supporting
  6. // documentation.
  7. //
  8. // Texas Instruments Incorporated provides this software "as is" without
  9. // express or implied warranty.
  10. //
  11.  
  12. #include <cool/String.h>
  13. #include <cool/Range.h>                    // Include range header file
  14.  
  15. #include <cool/Range.C>
  16. DECLARE CoolRange<double,2.5,8.8>;        // Declare CoolRange of doubles
  17. IMPLEMENT CoolRange<double,2.5,8.8>;        // Implement CoolRange of doubles
  18. DECLARE CoolRange<char*,"D", "K">;        // Declare CoolRange of strings
  19. IMPLEMENT CoolRange<char*, "D", "K">;        // Implement CoolRange of strings
  20.  
  21. extern int my_compare (const charP& s1, const charP& s2) {
  22.   return (strcmp (s1, s2));
  23. }
  24.  
  25. int main (void) {
  26.   CoolRange<double,2.5,8.8> r1;            // CoolRange-checked double
  27.   r1.set(4.3);                    // Assign value
  28.   cout << "r1 has an inclusive low bound of " << r1.low(); // Output low and
  29.   cout << ", an inclusive high bound of " << r1.high() << ",\n"; // High bounds
  30.   cout << "and a value of " << (double)r1 << "\n"; // Output value
  31.   double d1 = 1.9;                // Declare a double
  32.   cout << (double)r1 << " * " << d1 << " = ";    // Output equation
  33.   r1.set (d1 * r1);                // Calculate value
  34.   cout << (double)r1 << "\n";            // And display it
  35.   CoolRange<charP,"D","K"> r2;            // CoolRange-checked string
  36.   r2.set_compare (&my_compare);            // Set compare function
  37.   r2.set("EFG");                // Assign value
  38.   cout << "r2 has an inclusive low bound of " << r2.low();
  39.   cout << ", n inclusive high bound of " << r2.high() << ",\n";
  40.   cout << "a value of " << (char*)r2;        // Output string value
  41.   cout << ", and a length of " << strlen (r2) << "\n"; // Output length
  42.   return 0;                    // Exit with OK status
  43. }
  44.